package com.lie.flat.util;

import lombok.Data;


import java.util.HashMap;
import java.util.Map;


/**
 * 通用返回结果,服务端响应的数据最终都会封装成此对象。
 *
 * @param
 */
@Data
public class CommonReturn {

    private Integer code; //编码：1成功，0和其它数字为失败

    private String msg; //错误信息

    private Object data; //数据

    private Map<String, Object> map; //动态数据

    public static CommonReturn success(Object object) {
        CommonReturn commonReturn = new CommonReturn();
        commonReturn.data = object;
        commonReturn.code = 1;
        return commonReturn;
    }

    public static CommonReturn error(String msg) {
        CommonReturn commonReturn = new CommonReturn();
        commonReturn.msg = msg;
        commonReturn.code = 0;
        return commonReturn;
    }

    public CommonReturn add(String key, Object value) {
        map = new HashMap<>();
        map.put(key, value);
        return this;
    }

}
